<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>json.min.js - JSON压缩解压测试</title>
    <style>
        html, body {
            margin: 0;
            width: 100%;
            height:100%;
        }
        textarea {
            width: 45%;
            height: 400px;
        }
    </style>
</head>
<body>
<textarea id="t1">{"students":[{"name":"Jack","age":17},{"name":"Jill","age":16},{"name":"Sue","age":16}],"class":"math"}</textarea>
<button onclick="encode()">压缩</button> <button onclick="decode()">解压</button>
<textarea id="t2"></textarea>
<div id="put"></div>
</body>
<script src="json.min.js"></script>
<script>
    function encode(){
        put.innerHTML = '';
        putInfo('原始长度：' + t1.value.length);
        t2.value = JSON.encode(t1.value);
        putInfo('压缩后：' + t2.value.length);
    }

    function decode(){
        put.innerHTML = '';
        putInfo('原始长度：' + t2.value.length);
        t1.value = JSON.decode(t2.value);
        putInfo('解压后：' + t1.value.length);
    }

    function putInfo(s){
        put.innerHTML += s + '<br>';
    }
</script>
</html>